﻿using System;
using System.Windows;
using System.Windows.Controls;
using Baosight.Platform.Core;
using Baosight.ZNH.ZM.UI.PopWindows;
using Baosight.ZNH.ZMCommon;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using Baosight.Platform.Core.UI.Controls;

namespace Baosight.ZNH.ZM.UI
{
    /// <summary>
    /// 首页 安全模块 隐患
    /// </summary>
    /// Title:ZM94
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 郭淑芳
    /// Version: 1.0
    /// History:
    ///       2012-11-07  郭淑芳   [创建]
    ///  
    ///
    public partial class ZM94 : EFViewCmes
    {
        public ZM94()
        {
            InitializeComponent();
        }

        public override void Initialize(EIInfo initData)
        {
            untreated.Header = "未处理("+initData.Get("num1")+")";
            noFeedback.Header = "未整改(" + initData.Get("num2") + ")";
            noReview.Header = "未复查(" + initData.Get("num3") + ")";
            if (initData.Get("num1").Equals("0"))
            {
                isMore1.IsEnabled = false;
            }
            else if (initData.Get("num2").Equals("0"))
            {
                isMore2.IsEnabled = false;
            }
            else if (initData.Get("num3").Equals("0"))
            {
                isMore3.IsEnabled = false;
            }

            // 判断显示更多或者处理
            if ("no".Equals(initData.Get("isMore")))
            {
                this.isMore1.Content = "处理";
                this.isMore2.Content = "处理";
                this.isMore3.Content = "处理";
            }

            base.Initialize(initData);
        }

        /// <summary>
        /// 首页隐患--更多/处理--未处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_ClickA(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            link.IsEnabled = false;
            if (this.isMore1.Content.Equals("更多"))
            {
                Shell.LoadView("ZM9C");
            }
            else {
                Shell.LoadView("ZMCL70");
            }           
            link.IsEnabled = true;            
        }

        /// <summary>
        /// 首页隐患--更多/处理--未反馈
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_ClickB(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            link.IsEnabled = false;
            if (this.isMore2.Content.Equals("更多"))
            {
                Shell.LoadView("ZM9C");
            }
            else
            {
                Shell.LoadView("ZMCL73");
            }
            link.IsEnabled = true; 
        }

        /// <summary>
        /// 首页隐患--更多/处理--未复查
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_ClickC(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            link.IsEnabled = false;
            if (this.isMore3.Content.Equals("更多"))
            {
                Shell.LoadView("ZM9C");
            }
            else
            {
                Shell.LoadView("ZMCL70");
            }
        }

        /// <summary>
        /// 隐患信息 查看-未处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_Click1(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            EIRow row = (link.ParentOfType<GridViewRow>().Item as UIBaseEntity).GetEIRow();
            EIInfo eiInfo = new EIInfo();
            EIBlock eIBlock = new EIBlock("result");
            eIBlock.SetRow(0, row == null ? new EIRow() : row);
            eiInfo.AddBlock(eIBlock);

            base.OnHyperlinkButtonClickPopup(eiInfo, "隐患信息-查看", "detail", null, sender, e);
        }

        /// <summary>
        /// 隐患信息 查看-未反馈
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_Click2(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            EIRow row = (link.ParentOfType<GridViewRow>().Item as UIBaseEntity).GetEIRow();
            EIInfo eiInfo = new EIInfo();
            EIBlock eIBlock = new EIBlock("result");
            eIBlock.SetRow(0, row == null ? new EIRow() : row);
            eiInfo.AddBlock(eIBlock);

            base.OnHyperlinkButtonClickPopup(eiInfo, "隐患信息-查看", "detail", null, sender, e);
        }

        /// <summary>
        /// 隐患信息 查看-未复查
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_Click3(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            EIRow row = (link.ParentOfType<GridViewRow>().Item as UIBaseEntity).GetEIRow();
            EIInfo eiInfo = new EIInfo();
            EIBlock eIBlock = new EIBlock("result");
            eIBlock.SetRow(0, row == null ? new EIRow() : row);
            eiInfo.AddBlock(eIBlock);

            base.OnHyperlinkButtonClickPopup(eiInfo, "隐患信息-查看", "detail", null, sender, e);
        }

        /// <summary>
        /// 构造查看页面内容、弹出页面
        /// </summary>
        /// <param name="eIInfo"></param>
        /// <param name="title"></param>
        public override void OpenPopup(EIInfo eiInfo, string _title, string _dialogType, string _args)
        {
            RiskRecordDetail view = new RiskRecordDetail(_dialogType);//构造一个新的查看页面
            view.EIDataContext = new Platform.Core.UI.EIDataContext();
            eiInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cl.riskSource"));//隐患来源
            eiInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cl.riskLevel"));//隐患级别
            eiInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cl.riskClassify"));//隐患分类

            view.EIDataContext.Update(eiInfo);

            CmesWindows _popup = new CmesWindows();//构造一个弹出页面
            _popup.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterOwner;
            _popup.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
            _popup.Header = _title == null ? "" : _title;//设置Title
            _popup.Content = view;//让查看页面在弹出窗口显示
            _popup.Closed += new EventHandler<WindowClosedEventArgs>(CmesWindow_Closed);
            _popup.ShowDialog();//模态显示弹出窗口
        }

        /// <summary>
        /// 弹出窗口关闭时执行的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CmesWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            //按钮生效
            base.TempButtonOpen(true);

            //超链接生效
            if (base.TempHyperlink != null)
            {
                base.TempHyperlink.IsEnabled = true;
                base.TempHyperlink = null;
            }
        }

        private void TabSource_SelectionChanged(object sender, RoutedEventArgs e)
        {
            EFTab tab = sender as EFTab;
            if (tab.SelectedItem != null)
            {
                EFTabItem item = tab.SelectedItem as EFTabItem;
                if (tab.SelectedItem.Equals(untreated))
                {
                    if (untreated.Header.ToString().Substring(4,1).Equals("0"))
                    {
                        isMore1.IsEnabled = false;
                    }
                   
                }
                else if (tab.SelectedItem.Equals(noFeedback))
                {
                    if (noFeedback.Header.ToString().Substring(4, 1).Equals("0"))
                    {
                        isMore2.IsEnabled = false;
                    }
                }
                else if (tab.SelectedItem.Equals(noReview))
                {
                    if (noReview.Header.ToString().Substring(4, 1).Equals("0"))
                    {
                        isMore3.IsEnabled = false;
                    }
                }
            }
        }
    }
}
